package com.habdqn.studentmanager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.xiaofan1519.verify.core.Verify;
import com.github.xiaofan1519.verify.exception.VerifyException;
import com.habdqn.studentmanager.bean.Dictionary;
import com.habdqn.studentmanager.bean.ajax.Response;
import com.habdqn.studentmanager.constant.ErrorCode;
import com.habdqn.studentmanager.exception.StudentException;
import com.habdqn.studentmanager.service.DictionaryService;

/**
 * @author Fan
 * 字典控制器
 * 2017年7月20日
 * 
 */
@Controller
@RequestMapping("/dict")
public class DictionaryController extends BaseController {
    
    @Resource
    private DictionaryService dictService;
    
    /**
     * 获取指定类型下的字典集合
     * @param type
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Response list(Integer type) {
        
        try {
            Verify.verifyNull(type);
            Dictionary dict = new Dictionary();
            dict.setType(type);
            List<Dictionary> lists = dictService.findList(dict);
            return buildRsp(0, lists);
        }
        catch (VerifyException e) {
            logger.debug("参数非法", e);
            return buildRsp(ErrorCode.Invalid_Argument, "参数非法");
        }
        catch (StudentException e) {
            return buildRsp(ErrorCode.System_Error, e);
        }
    }
}
